package com.yuwei.recyclerviewdemo.adapter;

import android.content.Context;
import android.view.ViewGroup;

import java.util.List;

/**
 * @author 崔健伟
 * @version V1.0
 * @Title: MultiItemCommonAdapter.java
 * @Package com.yuwei.recyclerviewdemo
 * @Description: 第二层的抽象adapter，增加分类显示
 * @date 2016/11/20 15:25
 */
public abstract class MultiItemCommonAdapter<T> extends CommonAdapter<T> {
    //实现分类显示的接口
    protected MultiItemTypeSupport<T> mMultiItemTypeSupport;

    public MultiItemCommonAdapter(Context mContext, List<T> mDatas, MultiItemTypeSupport<T> multiItemTypeSupport) {
        super(mContext, -1, mDatas);
        mMultiItemTypeSupport = multiItemTypeSupport;
    }

    /**
     * @author: cuijianwei
     * @time: 2016/11/21 14:33
     * @desc: 通过接口获取每一个item的类型
     **/
    @Override
    public int getItemViewType(int position) {
        return mMultiItemTypeSupport.getItemViewType(position, position < mDatas.size() ? mDatas.get(position) : mDatas.get(position - 1));
    }

    /**
     * @author: cuijianwei
     * @time: 2016/11/21 14:37
     * @desc: 根据每一个item的类型返回相应的布局
     **/
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        int layoutId = mMultiItemTypeSupport.getLayoutId(viewType);
        ViewHolder holder = ViewHolder.get(mContext, parent, layoutId);
        return holder;
    }
}
